home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
monitordemo
/
monitor.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-10
|
17KB
|
681 lines
#ifndef lint
static char SccsId[]= "@(#)monitor.c V1.9 3/15/95";
#endif
/*
| file name - monitor.c
|===================================================================
|
| copyright (c) 1989
| V. I. Corporation
|
|===================================================================
|
| module description/function:
|
|===================================================================
*/
#include "std.h"
#include "dvstd.h"
#include "dvtools.h"
#include "VOstd.h"
#include "dvGR.h"
#include "Tfundecl.h"
#include "dvinteract.h"
#include "VUfundecl.h"
#include "VUerfundecl.h"
#include "VOfundecl.h"
#include "VTfundecl.h"
#include "GRfundecl.h"
#ifdef WINNT
#include <windows.h>
#endif /* WINNT */
/* This program can be linked to run:
|
| With 100% CPU usage (which shows updates in a tight loop)
| comment #define DV_USE_TIMER
| With Time-Outs (which show update based on a timer).
| uncomment #define DV_USE_TIMER
*/
#define DV_USE_TIMER
#ifdef DV_USE_TIMER
LOCAL INT TimeoutInterval = 25;
#ifdef WINNT
LOCAL HWND Hwnd;
LOCAL VOID CALLBACK TimeOutProc V_P_((HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime));
#else /* UNIX */
/* Include the X based files so we can add AppTimeOuts */
#ifdef CONST
#undef CONST
#endif
#ifndef __STDC__
#define _NO_PROTO
#endif
/* X11 include files */
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
LOCAL XtAppContext app_context;
LOCAL void UpdateProc V_P_((ADDRESS args, XtIntervalId *interval_id));
#endif /* WINNT */
#endif /* DV_USE_TIMER */
#define DEF_SEARCH_PATH (ADDRESS)NULL
#define DEF_DISPFORMS (ADDRESS)NULL
#define DEF_DEVICE (ADDRESS)NULL
#define DEF_COLORTAB (ADDRESS)NULL
#define DEF_SIZE (RECTANGLE*)NULL
#define DEF_PORTION (RECTANGLE*)NULL
LOCAL DRAWPORT CurrentDrawport;
LOCAL VIEW CurrentView;
LOCAL OBJECT DVscreen;
LOCAL SYMTABLE DrawportTable;
/* Define a structure that will keep track of NEXT & PREVIOUS displays */
typedef struct DISPLAY_LIST
{
DRAWPORT drawport;
struct DISPLAY_LIST *prev;
} DISPLAY_LIST;
LOCAL DISPLAY_LIST *DisplayList;
#define NUM_PRELOAD_VIEWS 6
LOCAL CHAR *ViewName[]=
{
"proc_WAN.v",
"proc_SITE.v",
"proc_OV.v",
"proc_PLT.v",
"proc_TB.v",
"proc_OL.v",
};
#define NEXT_DISPLAY 1
#define PREV_DISPLAY 2
#define RESET_DISPLAY 3
/* Hot Spot Names */
#define QUIT_COMMAND 'Q'
#define NEXT_COMMAND 'N'
#define RETURN_COMMAND 'R'
/***************** Begin Function Declarations *************/
LOCAL void UpdateDisplay V_P_((void));
LOCAL void LoadViews V_P_((void));
LOCAL DRAWPORT init_drawport V_P_((char *viewname));
LOCAL void SwitchDisplay V_P_((int choice, char *view_name));
LOCAL DRAWPORT next_display V_P_((char *view_name));
LOCAL DRAWPORT prev_display V_P_((void));
LOCAL DRAWPORT reset_display V_P_((void));
LOCAL DISPLAY_LIST *create_display_list V_P_((void));
LOCAL void del_display_list_item V_P_((DISPLAY_LIST *display_item));
LOCAL void FreeDisplayList V_P_((DISPLAY_LIST **display_info));
LOCAL DRAWPORT get_drawport V_P_((char *view_name));
LOCAL void HandlePick V_P_((OBJECT loc));
LOCAL void QuitProgram V_P_((void));
LOCAL char *StrClone V_P_((char * string));
/***************** End Function Declarations *************/
#ifdef WINNT
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
#else /* Not WINNT */
int
main (argc, argv)
int argc;
char *argv[];
#endif /* WINNT */
{
OBJECT location;
int error_code;
char buf[50];
/* Initialize the DataViews Environment */
(VOID) TInit (DEF_SEARCH_PATH, DEF_DISPFORMS);
/* Open a window */
VUon_copyright ();
DVscreen = TscOpenSet (DEF_DEVICE, DEF_COLORTAB,
V_WINDOW_NAME, "DataViews Monitor Demo",
#ifdef WINNT
V_WIN32_ICON_NAME, "monitoricon",
#ifdef DOUBLE_BUFFER
V_WIN32_DOUBLE_BUFFER, YES,
#endif /* DOUBLE_BUFFER */
#else /* Not WINNT */
V_X_EXPOSURE_BLOCK, YES,
#endif /* WINNT */
V_INITIAL_CURSOR,
V_END_OF_LIST);
if(!DVscreen)
{
error_code=TscOpenError();
#ifdef WINNT
sprintf(buf,"Product is not validated. Error code %d.",error_code);
MessageBox(NULL,buf,"Validation Error",MB_OK);
#else
fprintf(stderr,"Product is not validated. Error code %d.",error_code);
#endif
exit(error_code);
}
/* Setup the window events */
(VOID) VOscWinEventMask ((ULONG) (V_KEYPRESS |
V_BUTTONPRESS |
V_RESIZE | V_EXPOSE |
V_WINDOW_QUIT),
(ULONG) V_END_OF_LIST);
#ifdef DV_USE_TIMER
#ifdef WINNT
/* Get the Windows based information */
(VOID) GRget (V_WIN32_WINDOW_HANDLE, &Hwnd, V_END_OF_LIST);
/* Post a timeout for dynamic updates
| The timeout procedure will update the dynamics of
| all screens which have been opened. The procedure is invoked
| whenever the specified time interval elapses. The interval is
| specified in milliseconds.
*/
SetTimer (Hwnd, (UINT)Hwnd, TimeoutInterval, (TIMERPROC)TimeOutProc);
#else /* UNIX */
/* Extract the X information so we can setup a Time-Out Proc
| for updating....
| Get the Xt Application Context information.
| Post a timeout procedure will update the dynamics of
| all screens which have been opened. The procedure is invoked
| whenever the specified time interval elapses. The interval is
| specified in milliseconds.
*/
(VOID) GRget (V_X_APPLIC_CONTEXT, &app_context, V_END_OF_LIST);
XtAppAddTimeOut (app_context, TimeoutInterval,
(XtTimerCallbackProc) UpdateProc, NULL);
#endif /* WINNT */
#endif /* DV_USE_TIMER */
/* Load the views and draws the first one */
LoadViews ();
/* Change the cursor */
(VOID) GRset (V_ACTIVE_CURSOR, 0);
FOREVER
{
#ifdef DV_USE_TIMER
/* Gather and Process User Inputs
| Note: since we posted a time-out, the event
| handler will call our function to handle
| the updating of dynamic objects.
*/
location = VOloWinEventPoll (V_WAIT);
#else /* Not DV_USE_TIMER */
/* Update the Display */
UpdateDisplay();
/* Get the Event */
location = VOloWinEventPoll( V_NO_WAIT );
#endif /* DV_USE_TIMER */
if (location)
{
switch (VOloType (location))
{
case V_EXPOSE:
(VOID) TscRedraw (DVscreen, VOloRegion (location));
break;
case V_RESIZE:
(VOID) TscReset (DVscreen);
break;
case V_WINDOW_QUIT:
QuitProgram ();
break;
case V_KEYPRESS:
case V_BUTTONPRESS:
(VOID) VUerHandleLocEvent (location);
(VOID) HandlePick (location);
break;
} /* end switch */
} /* end if */
} /* end FOREVER */
return 1;
}
LOCAL void
UpdateDisplay
V_P_ ((void))
{
/* Update the current View */
(VOID) TviReadData (CurrentView);
(VOID) TdpDrawNext (CurrentDrawport);
}
#ifdef DV_USE_TIMER
#ifdef WINNT
/*ARGSUSED*/
LOCAL VOID CALLBACK
TimeOutProc (hwnd, uMsg, idEvent, dwTime)
HWND hwnd;
UINT uMsg;
UINT idEvent;
DWORD dwTime;
{
UpdateDisplay ();
}
#else /* UNIX */
/*ARGSUSED*/
LOCAL void
UpdateProc (args, interval_id)
ADDRESS args;
XtIntervalId *interval_id;
{
UpdateDisplay ();
/* Re-Post the Time-Out */
XtAppAddTimeOut (app_context, TimeoutInterval,
(XtTimerCallbackProc) UpdateProc, NULL);
}
#endif /* WINNT */
#endif /* DV_USE_TIMER */
/*-----------------------------------------------------------------
|
| LoadViews
| This function Pre-Loads the views....
*/
LOCAL void LoadViews
V_P_ ((void))
{
INT i;
/* Initialize the symbol table used for storing views */
DrawportTable = VTstcreate ("ViewName/Drawport", (VTSTCOMPAREFUNPTR)NULL);
/* Load and Draw the first View */
(VOID) init_drawport (ViewName[0]);
SwitchDisplay (NEXT_DISPLAY, ViewName[0]);
/* For all the room views... load the view, create a drawport, add the
| drawport to the symbol table.
*/
for (i = 1; i < NUM_PRELOAD_VIEWS; i++)
(VOID) init_drawport (ViewName[i]);
}
/*-----------------------------------------------------------------
|
| init_drawport
| The function creates a drawport in the specified area to
| display the specified view.
|
| The drawport is added to the symbol tables for easy
| access by the display manager routines.
|
*/
LOCAL DRAWPORT
init_drawport (viewname)
char *viewname;
{
VIEW view;
DRAWPORT drawport = NULL;
RECTANGLE wvp, dummy;
/* Load the view */
view = TviLoad (viewname);
if (view)
{
/* Setup the data */
(VOID) TviOpenData (view);
/* Setup a drawport */
VOobBox (TviGetDrawing (view), &wvp, &dummy);
drawport = TdpCreateStretch (DVscreen, view, DEF_SIZE, &wvp);
/* Add the drawport to the table */
(VOID) VTstsninsert (DrawportTable,
(CHAR *) StrClone (viewname), (INT *) drawport);
}
return drawport;
}
/*-----------------------------------------------------------------
|
| SwitchDisplay
| Switches the view being displayed in the MONITOR AREA.
|
| The views are managed in a "DisplayList" which is
| updated according to the "choice".
| next_display() - Adds a display to the list.
| prev_display() - Deletes a display from the list.
|
| This allows us to keep a history of where we've been.
|
| The old display is terminated before the new display is
| drawn;
*/
LOCAL void
SwitchDisplay (choice, view_name)
int choice;
char *view_name;
{
DRAWPORT new_dp = NULL;
/* If they switch to the top display, reset the NEXT/PREV list */
if (view_name && S_STRCMP (view_name, ViewName[0]) == 0)
choice = RESET_DISPLAY;
/* Switch displays according to the choice */
switch (choice)
{
case PREV_DISPLAY:
new_dp = prev_display ();
break;
case NEXT_DISPLAY:
new_dp = next_display (view_name);
break;
case RESET_DISPLAY:
new_dp = reset_display ();
break;
default:
break;
}
/* If we can successfully switch displays, cleanup and continue */
if (new_dp)
{
/* Draw the new display */
CurrentDrawport = new_dp;
CurrentView = TdpGetView (new_dp);
(VOID) TdpDraw (CurrentDrawport);
}
}
/*-----------------------------------------------------------------
|
| next_display
| Tries to add a display to the DisplayList. If the view can't
| be displayed, returns DV_FAILURE, else DV_SUCCESS.
|
*/
LOCAL DRAWPORT
next_display (view_name)
char *view_name;
{
DISPLAY_LIST *prev_display;
DRAWPORT dp;
/* Get the drawport associated with the view */
dp = get_drawport (view_name);
if (dp)
{
/* If the list doesn't exist yet, create it.
|
| Make the current list top the previous display. Then,
| make the new display the list top. */
if (!DisplayList)
{
prev_display = create_display_list ();
prev_display->drawport = CurrentDrawport;
}
else
prev_display = DisplayList;
DisplayList = create_display_list ();
DisplayList->drawport = dp;
DisplayList->prev = prev_display;
}
return dp;
}
/*-----------------------------------------------------------------
|
| prev_display
| If their is a previous display, make it the top and
| deletes the current from the list.
*/
LOCAL DRAWPORT prev_display
V_P_ ((void))
{
DISPLAY_LIST *prev_display;
/* Make sure we have a list and a previous display before
| you make the previous display the top.
*/
if (DisplayList && DisplayList->prev)
{
prev_display = DisplayList->prev;
del_display_list_item (DisplayList);
DisplayList = prev_display;
return DisplayList->drawport;
}
else
return (DRAWPORT) NULL;
}
/*-----------------------------------------------------------------
|
| reset_display
| Resets the Display List, deletes the previous list and makes
| the TOP_VIEW the beginning of the list.
*/
LOCAL DRAWPORT reset_display
V_P_ ((void))
{
/* Destroy the DisplayList */
FreeDisplayList (&DisplayList);
/* return the Active Drawport to the Top View */
return get_drawport (ViewName[0]);
}
/*-----------------------------------------------------------------
|
| create_display_list - Allocates and initializes a DISPLAY_LIST.
*/
LOCAL DISPLAY_LIST *create_display_list
V_P_ ((void))
{
DISPLAY_LIST *display_info;
display_info = (DISPLAY_LIST *) S_ALLOC ((LONG) sizeof (DISPLAY_LIST));
display_info->drawport = (DRAWPORT) NULL;
display_info->prev = (DISPLAY_LIST *) NULL;
return display_info;
}
/*-----------------------------------------------------------------
|
| del_display_list_item - Frees a DISPLAY_LIST item.
*/
LOCAL void
del_display_list_item (display_item)
DISPLAY_LIST *display_item;
{
S_FREE ((CHAR *) display_item);
}
/*-----------------------------------------------------------------
|
| FreeDisplayList - Destroys the DISPLAY_LIST by freeing each item.
*/
LOCAL void
FreeDisplayList (display_info)
DISPLAY_LIST **display_info;
{
DISPLAY_LIST *info, *prev;
info = *display_info;
while (info)
{
prev = info->prev;
del_display_list_item (info);
info = prev;
}
*display_info = NULL;
}
/*-----------------------------------------------------------------
|
| get_drawport
| Returns the drawport associated with the view_name. If the
| drawport doesn't exist, it creates one.
*/
LOCAL DRAWPORT
get_drawport (view_name)
char *view_name;
{
SYMNODE table_entry;
/* See if the drawport is already in the Drawport Table */
table_entry = VTstkeyfind (DrawportTable, view_name);
if (table_entry)
return (DRAWPORT) VTsnvalue (table_entry);
else
return init_drawport (view_name);
}
/*-----------------------------------------------------------------
|
| HandlePick
| Processes user picks.
|
| Checks to see if we've selected a named object. If we have
| it parses the command embedded in the name.
|
| Only the first letter of the name is used for the command.
| The commands have the following meanings:
|
| Quit - Quits the application
| N:<viewname> - The NEXT view is displayed
| Return - RETURN to the previous view
*/
LOCAL void
HandlePick (loc)
OBJECT loc;
{
CHAR *obj_name, *cmd;
/* Find the selected object */
obj_name = TloGetSelectedObjectName (loc);
/* Handle the command associated with the object's name */
if (obj_name)
{
cmd = obj_name;
/* Process the current command */
switch ((INT) cmd[0])
{
/* NEXT Display */
case NEXT_COMMAND:
SwitchDisplay (NEXT_DISPLAY, &cmd[2]);
break;
/* RETRUN display */
case RETURN_COMMAND:
SwitchDisplay (PREV_DISPLAY, (CHAR *) NULL);
break;
/* QUIT the application */
case QUIT_COMMAND:
QuitProgram ();
break;
}
}
}
LOCAL void QuitProgram
V_P_ ((void))
{
VIEW view;
CHAR *view_name;
SYMNODE table_entry;
DRAWPORT dp;
/* Destroy the window's display list */
FreeDisplayList (&DisplayList);
/* Destroy all the drawports in the drawport table */
while (VTstlen (DrawportTable) > 0)
{
table_entry = VTstsnget (DrawportTable, 0);
view_name = VTsnkey (table_entry);
S_FREE ((ADDRESS) view_name);
dp = (DRAWPORT) VTsnvalue (table_entry);
view = TdpGetView (dp);
(VOID) TdpDestroy (dp);
(VOID) TviCloseData (view);
(VOID) TviDestroy (view);
VTstsnremove (DrawportTable, table_entry);
}
/* Destroy the drawport table */
VTstdestroy (DrawportTable);
(VOID) TscErase (DVscreen);
(VOID) TscClose (DVscreen);
(VOID) TTerminate ();
S_EXIT (0);
}
/*==================================================================
|
| StrClone
| Allocates space for and makes a copy of a specified string,
| returning a pointer to the string. If there is no input
| string, the routine returns a NULL.
*/
LOCAL CHAR *StrClone( str )
CHAR *str;
{
FAST INT len;
CHAR *newstr;
FAST CHAR *to;
FAST CHAR *from;
if( str == NULL )
return( NULL );
len = S_STRLEN( str ) + 1;
newstr = (CHAR *)S_ALLOC( len );
if( newstr )
for( to = newstr, from = str; len > 0; len-- )
*to++ = *from++;
return( newstr );
}